from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-08 14:09:04.078346
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 08, Feb, 2021
Time: 14:09:08
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9620
Nobs: 196.000 HQIC: -46.8578
Log likelihood: 2238.78 FPE: 2.42992e-21
AIC: -47.4672 Det(Omega_mle): 1.55271e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.467728 0.142175 3.290 0.001
L1.Burgenland 0.086989 0.073361 1.186 0.236
L1.Kärnten -0.219121 0.061261 -3.577 0.000
L1.Niederösterreich 0.128297 0.170284 0.753 0.451
L1.Oberösterreich 0.250671 0.149061 1.682 0.093
L1.Salzburg 0.199414 0.078964 2.525 0.012
L1.Steiermark 0.091307 0.106089 0.861 0.389
L1.Tirol 0.152932 0.071567 2.137 0.033
L1.Vorarlberg -0.001267 0.065283 -0.019 0.985
L1.Wien -0.143143 0.143075 -1.000 0.317
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.495480 0.173412 2.857 0.004
L1.Burgenland 0.016037 0.089478 0.179 0.858
L1.Kärnten 0.363314 0.074721 4.862 0.000
L1.Niederösterreich 0.126126 0.207697 0.607 0.544
L1.Oberösterreich -0.146719 0.181810 -0.807 0.420
L1.Salzburg 0.196726 0.096313 2.043 0.041
L1.Steiermark 0.233805 0.129398 1.807 0.071
L1.Tirol 0.132327 0.087290 1.516 0.130
L1.Vorarlberg 0.173876 0.079626 2.184 0.029
L1.Wien -0.578947 0.174510 -3.318 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.306339 0.062753 4.882 0.000
L1.Burgenland 0.106637 0.032380 3.293 0.001
L1.Kärnten -0.021295 0.027039 -0.788 0.431
L1.Niederösterreich 0.070011 0.075160 0.931 0.352
L1.Oberösterreich 0.285107 0.065792 4.333 0.000
L1.Salzburg 0.004967 0.034853 0.143 0.887
L1.Steiermark -0.020016 0.046826 -0.427 0.669
L1.Tirol 0.091067 0.031588 2.883 0.004
L1.Vorarlberg 0.111469 0.028815 3.868 0.000
L1.Wien 0.071161 0.063151 1.127 0.260
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.223463 0.071320 3.133 0.002
L1.Burgenland -0.013805 0.036800 -0.375 0.708
L1.Kärnten 0.024140 0.030731 0.786 0.432
L1.Niederösterreich 0.034551 0.085420 0.404 0.686
L1.Oberösterreich 0.383210 0.074774 5.125 0.000
L1.Salzburg 0.094604 0.039611 2.388 0.017
L1.Steiermark 0.185891 0.053218 3.493 0.000
L1.Tirol 0.040293 0.035900 1.122 0.262
L1.Vorarlberg 0.091148 0.032748 2.783 0.005
L1.Wien -0.065761 0.071771 -0.916 0.360
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.523859 0.142488 3.677 0.000
L1.Burgenland 0.059562 0.073522 0.810 0.418
L1.Kärnten 0.016470 0.061396 0.268 0.789
L1.Niederösterreich -0.023987 0.170659 -0.141 0.888
L1.Oberösterreich 0.151704 0.149389 1.015 0.310
L1.Salzburg 0.056235 0.079138 0.711 0.477
L1.Steiermark 0.125810 0.106323 1.183 0.237
L1.Tirol 0.206410 0.071724 2.878 0.004
L1.Vorarlberg 0.030516 0.065427 0.466 0.641
L1.Wien -0.136141 0.143390 -0.949 0.342
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160880 0.100552 1.600 0.110
L1.Burgenland -0.019818 0.051884 -0.382 0.702
L1.Kärnten -0.011777 0.043326 -0.272 0.786
L1.Niederösterreich 0.119543 0.120432 0.993 0.321
L1.Oberösterreich 0.388854 0.105422 3.689 0.000
L1.Salzburg -0.019948 0.055847 -0.357 0.721
L1.Steiermark -0.025258 0.075031 -0.337 0.736
L1.Tirol 0.189603 0.050615 3.746 0.000
L1.Vorarlberg 0.035776 0.046171 0.775 0.438
L1.Wien 0.189641 0.101189 1.874 0.061
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.239230 0.129580 1.846 0.065
L1.Burgenland 0.055989 0.066862 0.837 0.402
L1.Kärnten -0.040969 0.055834 -0.734 0.463
L1.Niederösterreich -0.035422 0.155199 -0.228 0.819
L1.Oberösterreich -0.084610 0.135856 -0.623 0.533
L1.Salzburg 0.035557 0.071969 0.494 0.621
L1.Steiermark 0.393410 0.096691 4.069 0.000
L1.Tirol 0.492047 0.065227 7.544 0.000
L1.Vorarlberg 0.169974 0.059500 2.857 0.004
L1.Wien -0.223637 0.130401 -1.715 0.086
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.076202 0.155473 0.490 0.624
L1.Burgenland 0.028824 0.080222 0.359 0.719
L1.Kärnten -0.087879 0.066991 -1.312 0.190
L1.Niederösterreich 0.242567 0.186211 1.303 0.193
L1.Oberösterreich -0.004793 0.163002 -0.029 0.977
L1.Salzburg 0.233861 0.086349 2.708 0.007
L1.Steiermark 0.133784 0.116011 1.153 0.249
L1.Tirol 0.071824 0.078260 0.918 0.359
L1.Vorarlberg 0.043574 0.071389 0.610 0.542
L1.Wien 0.268402 0.156457 1.716 0.086
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.595219 0.082133 7.247 0.000
L1.Burgenland -0.027313 0.042380 -0.644 0.519
L1.Kärnten -0.002775 0.035390 -0.078 0.937
L1.Niederösterreich -0.039315 0.098372 -0.400 0.689
L1.Oberösterreich 0.292785 0.086111 3.400 0.001
L1.Salzburg 0.016937 0.045617 0.371 0.710
L1.Steiermark 0.012702 0.061287 0.207 0.836
L1.Tirol 0.079335 0.041343 1.919 0.055
L1.Vorarlberg 0.137758 0.037714 3.653 0.000
L1.Wien -0.060522 0.082653 -0.732 0.464
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.139862 0.035875 0.205579 0.256554 0.064067 0.106402 -0.057061 0.176158
Kärnten 0.139862 1.000000 0.014970 0.190288 0.160975 -0.113408 0.165979 0.020991 0.310347
Niederösterreich 0.035875 0.014970 1.000000 0.311367 0.084538 0.216233 0.144203 0.052793 0.367627
Oberösterreich 0.205579 0.190288 0.311367 1.000000 0.302210 0.294723 0.112237 0.080520 0.136084
Salzburg 0.256554 0.160975 0.084538 0.302210 1.000000 0.153490 0.063523 0.088983 -0.016732
Steiermark 0.064067 -0.113408 0.216233 0.294723 0.153490 1.000000 0.103766 0.091074 -0.089345
Tirol 0.106402 0.165979 0.144203 0.112237 0.063523 0.103766 1.000000 0.161566 0.157554
Vorarlberg -0.057061 0.020991 0.052793 0.080520 0.088983 0.091074 0.161566 1.000000 0.072535
Wien 0.176158 0.310347 0.367627 0.136084 -0.016732 -0.089345 0.157554 0.072535 1.000000